/**
 * Created by Joe on 2017/2/19.
 */
public class StringTest {
    public static void main(String[] args) {
        String str = "Hello World";

        /* 截取字符串 substring*/
        String string1 = str.substring(6, 11);
        System.out.println(string1);

        /* 连接字符串 concat*/
        String concatString = "Yes ";
        String string2 = concatString.concat(str);
        System.out.println(string2);

        /* 替换字符串 replace*/
        String string3 = str.replace("Hello", "123");
        System.out.println(string3);

        /* 去除首尾空格 trim*/
        String string4 = " TRIM ".trim();
        System.out.println(string4);

        /* 转换为小写  toLowerCase*/
        String string5 = str.toLowerCase();
        System.out.println(string5);

        /* 转换为大写  toUpperCase*/
        String string6 = str.toUpperCase();
        System.out.println(string6);

        /* 字符串长度 length*/
        int len = str.length();
        System.out.println(len);

        /* 截取一个字符 charAt */
        char ch = str.charAt(6);
        System.out.println(ch);

        /* bytes */
        String string7 = "Hello!你好!";
        byte[] bytes = string7.getBytes();
        System.out.println(bytes[0]);

        /* 字符串转字符数组 */
        String string8 = "Hello!你好!";
        char[] chs = string8.toCharArray();
        System.out.println(chs[0]);

        /* 字符串比较函数 */
        if (!str.equals("1111")) {
            System.out.println("字符串不一样");
        }

        /* 是否以特定字符开始 */
        if (str.startsWith("Hello")) {
            System.out.println("以Hello开头");
        }

        /* 是否以特定字符结尾 */
        if (str.endsWith("World")) {
            System.out.println("以World结尾");
        }

        /* 查找字符出现位置 */
        int ddd = str.indexOf("W");
        System.out.println(ddd);
    }
}
